import { NgModule } from '@angular/core';
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
import { PreloadSelectedModulesService } from './selective-preload-strategy';
import { IndexComponent } from './index.component';
import { HelloAngularComponent } from './hello-angular/hello-angular.component';
import { FormsModule } from '@angular/forms';
import { AuthGuard } from './share/auth-guard.service';

export const routes: Routes = [
    { path: '', redirectTo: 'index', pathMatch: 'full' },
    { path: 'index', component: IndexComponent },
    { path: 'hero-form', loadChildren: 'app/template-form/hero-form.module#HeroFormModule', data: { preload: true } },
    { path: 'dynamic-form', loadChildren: 'app/dynamic-form/dynamic-form.module#DynamicFormModule' },
    {
        path: 'attribute-directives',
        loadChildren: 'app/attribute-directives/attribute-directives.module#AttributeDirectivesModule',
        data: { preload: true }
    },
    { path: 'hierachical-DI', loadChildren: 'app/hierachical-DI/hierachical-DI.module#HierachicalDIModule', data: { preload: true } },
    { path: 'http', loadChildren: 'app/http/http.module#HttpModule', data: { preload: true } },
    { path: 'lifecycle', loadChildren: 'app/lifecycle/lifecycle.module#LifecycleModule' },
    { path: 'pipes', loadChildren: 'app/pipes/pipes.module#PipesModule', data: { preload: true } },
    { path: 'sample-reddit', loadChildren: 'app/sample-reddit/sample-reddit.module#SampleRedditModule', data: { preload: true } },
    { path: 'router', loadChildren: 'app/router/router.module#RouterModule', data: { preload: true } },
    { path: 'admin', loadChildren: 'app/admin/admin.module#AdminModule', canLoad: [AuthGuard] },
    { path: 'login', loadChildren: 'app/login/login.module#LoginModule' },
    { path: 'rxjs-demo', loadChildren: 'app/rxjs/rxjs.module#RxjsModule', data: { preload: true } },
    { path: '**', redirectTo: 'index', pathMatch: 'full' }
];

@NgModule({
    // imports: [FormsModule, RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })],
    imports: [FormsModule, RouterModule.forRoot(routes, { preloadingStrategy: PreloadSelectedModulesService })],
    declarations: [IndexComponent, HelloAngularComponent],
    exports: [RouterModule]
})
export class AppRoutingModule { }
